
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="imgs/bai.ico">
    <link rel="Shortcut Icon" href="imgs/bai.ico"/>
    <link rel="stylesheet" type="text/css" href="css/view.css"/>
    <title>首页</title>
    <style type="text/css">
        #tbody { margin-top: 40%; text-align: center; }
        .group { margin: 10px 10vw; width: 80vw; }
        .group .title { text-align: left; font-size: 20px; font-weight: bolder; color: #555; }
        .group input { margin: 5px 0; padding: 10px 5%; width: 100%; border: 1px solid #ccc; border-radius: 10px; }
        .group button { margin: 5px 0; padding: 10px; width: 100%; border: 0; border-radius:5px; background: #0088CC; color: #eee; }
    </style>
</head>
<body>
<div id="tbody">
    <h4>工时管理</h4>
    <div class="group">
        <!--<div class="title">账号</div>-->
        <input type="text" id="uname" placeholder="输入账号" value=""/>
    </div>
    <div class="group">
        <input type="password" id="passwd" placeholder="输入密码" value=""/>
    </div>
    <div class="group">
        <button onclick="dologin();">立 即 登 录</button>
    </div>
</div>

<span id="msgPop"></span>
</body>
</html>


<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/view.js"></script>
<script type="text/javascript">
    var cw = document.documentElement.clientWidth;
    var ch = document.documentElement.clientHeight;
    (function () {
        if (cw > 500) {
            $('body').html('请使用手机打开'); return
        }
    })();
    function dologin(){
        var formData = {
            uname: $('#uname').val(),
            passwd: $('#passwd').val(),
        };
        var errMsg = $('#errMsg');
        if (formData.uname == '') {
            errMsg.html('账号必须的'); return
        }
        if (formData.passwd == '') {
            errMsg.html('密码必须的'); return
        }
        $.ajax({
            type: 'post',
            url: apiDomain + 'dologin',
            data: formData,
            success: function (res) {
                console.log(res);
                if (res.code < 0) {
                    errMsg.html(res.msg);
                    msgPop({msg: res.msg}); return
                }
                var userInfo = {
                    uid: res.data.uid,
                    uname: res.data.uname,
                    role_id: res.data.role_id,
                    role_name: res.data.role_name,
                    depart_id: res.data.depart_id,
                    depart_name: res.data.depart_name,
                    depart_lead: res.data.depart_lead,
                    logtime: res.data.logtime,
                };
                setUserInfo({val: userInfo});
                msgPop({msg: '登录成功'});
                setTimeout(function(){
                    window.location.href = 'index.html';
                }, 500);
            },
            error: function (err) {
                console.log(err);
            }
        });
    }
</script>